package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.accountuser.*;
import com.jinmdz.fmis.api.admin.service.AccountUserService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.model.SearchLoadData;
import com.jinmdz.fmis.dao.admin.model.accountuser.AccountUserListData;
import com.jinmdz.fmis.dao.admin.model.accountuser.AccountUserListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 帐号用户维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-17 11:03
 */
@Api(description = "帐号用户维护信息相关接口")
@RestController()
@RequestMapping("/admin/account-user")
public class AccountUserController extends BaseController {

    @Resource
    private AccountUserService accountUserService;

    /**
     * 加载帐号用户信息
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-03-17 11:05
     */
    @ApiOperation(value = "根据查询条件加载表【system_user】中保存的单位用户数据", notes = "根据查询条件加载表【system_user】中保存的单位用户数据")
    @PostMapping("/load-account-user-list")
    public BaseResult<SearchLoadData<AccountUserListItem>> loadAccountUserList(@RequestBody AccountUserListData data) {
        return resultHandler(data, userItem -> accountUserService.loadAccountUserList(data));
    }

    /**
     * 加载帐号用户信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-17 11:05
     */
    @ApiOperation(value = "根据【system_user】表中id加载帐号用户信息", notes = "根据ID加载帐号用户信息")
    @PostMapping("/load-account-user-with-id")
    public BaseResult<AccountUserLoadData> loadAccountUserWithId(@RequestBody AccountUserIdData data) {
        return resultHandler(data, userItem -> accountUserService.loadAccountUserWithId(data));
    }

    /**
     * 保存帐号用户信息到system_user表中
     *
     * @param data 请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-17 11:06
     */
    @ApiOperation(value = "保存帐号用户信息到【system_user】表中", notes = "保存帐号用户信息到【system_user】表中")
    @PostMapping("/save-account-user")
    public BaseResult saveAccountUser(@RequestBody AccountUserSaveData data) {
        return resultHandler(data, userItem -> accountUserService.saveAccountUser(userItem, data));
    }

    /**
     * 从system_user表中删除指定id的帐号用户信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-17 11:07
     */
    @ApiOperation(value = "从system_user表中删除指定id的帐号用户信息记录", notes = "从system_user表中删除指定id的帐号用户信息")
    @PostMapping("/delete-account-user-with-id")
    public BaseResult deleteAccountUserWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> accountUserService.deleteAccountUserWithId(userItem, data));
    }

    /**
     * 根据用户部门id加载表【system_user】中保存的用户数据，用于机构树中加载用户信息
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-03-25 16:48
     */
    @ApiOperation(value = "根据用户部门id加载表【system_user】中保存的用户数据，用于机构树中加载用户信息", notes = "根据用户部门id加载表【system_user】中保存的用户数据，用于机构树中加载用户信息")
    @PostMapping("/load-account-user-tree-with-department-id")
    public BaseResult<ArrayList<AccountUserTreeItem>> loadAccountUserTreeWithDepartmentId(@RequestBody AccountDepartmentIdData data) {
        return resultHandler(data, userItem -> accountUserService.loadAccountUserTreeWithDepartmentId(data));
    }
}
